package com.msa.msaportal.dao.impl;

import java.util.List;

import com.msa.msaportal.common.hibernate.Finder;
import com.msa.msaportal.common.hibernate.HibernateBaseDao;
import com.msa.msaportal.dao.IPortalCssEntityDao;
import com.msa.msaportal.entity.PortalCssEntity;

public class PortalCssEntityDaoImpl extends HibernateBaseDao<PortalCssEntity, Integer> implements IPortalCssEntityDao {

	@SuppressWarnings("unchecked")
	public List<PortalCssEntity> getcssEntityListByorgId(String orgId) {
		
		Finder finder = Finder.create();
		String hql = "from PortalCssEntity bean where bean.orgid=:orgCode";

		finder.append(hql);
		finder.setParam("orgCode", orgId);
		finder.append(" or bean.ispublic=:ispublic");
		finder.setParam("ispublic", true);
		return find(finder);
	}

	@Override
	protected Class<PortalCssEntity> getEntityClass() {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public void addCss(PortalCssEntity c) {
		// TODO Auto-generated method stub
		this.getSession().save(c);
	}
	@Override
	public void delCss(String csource_id) {
		// TODO Auto-generated method stub
		String hql="from PortalCssEntity c where c.csourceId=?";
		PortalCssEntity css = (PortalCssEntity) this.findUnique(hql, csource_id);
		
		//this.sessionFactory.getCurrentSession().delete(css);
		this.getSession().delete(css);
	}

	@Override
	public PortalCssEntity findByCsourse_Id(String csource_id) {
		// TODO Auto-generated method stub
		String hql="from PortalCssEntity c where c.csourceId=?";
		PortalCssEntity css = (PortalCssEntity) this.findUnique(hql, csource_id);
		return css;
	}

	@Override
	public PortalCssEntity findById(Integer cssid) {
		PortalCssEntity entity = (PortalCssEntity) this.getSession().get(PortalCssEntity.class, cssid);
		return entity;
	}

	@Override
	public void updateCssEntity(PortalCssEntity cssEntity) {
		
		this.getSession().update(cssEntity);
	}
}
